<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="公司名称" prop="orgName">
        <el-input
          v-model="queryParams.orgName"
          placeholder="请输入公司名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否国高薪企业" prop="isHpEnterprise">
        <el-select v-model="queryParams.isHpEnterprise" placeholder="请选择是否国高薪企业" clearable size="small">
          <el-option
            v-for="dict in isHpEnterpriseOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="负责人姓名" prop="principalName">
        <el-input
          v-model="queryParams.principalName"
          placeholder="请输入人力资源分管负责人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人电话" prop="principalPhone">
        <el-input
          v-model="queryParams.principalPhone"
          placeholder="请输入人力资源分管负责人电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人微信" prop="principalWx">
        <el-input
          v-model="queryParams.principalWx"
          placeholder="请输入人力资源分管负责人微信"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在镇街园区" prop="orgAddr">
        <el-select v-model="queryParams.orgAddr" placeholder="请选择所在镇街园区" clearable size="small">
          <el-option
            v-for="dict in orgAddrOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="拟引进人才姓名" prop="talentName">
        <el-input
          v-model="queryParams.talentName"
          placeholder="请输入拟引进人才姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生年月" prop="birthday">
        <el-date-picker
          v-model="queryParams.birthday"
          clearable
          size="small"
          type="month"
          value-format="yyyy-MM"
          placeholder="选择出生年月"
        />
      </el-form-item>
      <el-form-item label="本单位入职时间" prop="hiredate">
        <el-date-picker
          v-model="queryParams.hiredate"
          clearable
          size="small"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择本单位入职时间"
        />
      </el-form-item>
      <el-form-item label="是否留学生" prop="isForeignStudent">
        <el-select v-model="queryParams.isForeignStudent" placeholder="请选择是否留学生" clearable size="small">
          <el-option
            v-for="dict in isForeignStudentOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核结果" prop="result">
        <el-select v-model="form.result" placeholder="请选择审核结果">
          <el-option
            v-for="dict in resultOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['talent:talentBaseInfo:add']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['talent:talentBaseInfo:edit']"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['talent:talentBaseInfo:remove']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['talent:talentBaseInfo:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="talentBaseInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="主键" align="center" prop="talentBaseInfoId" />-->
      <el-table-column label="公司名称" align="center" prop="orgName" />
      <el-table-column label="是否国高薪企业" align="center" prop="isHpEnterprise" :formatter="isHpEnterpriseFormat" />
      <el-table-column label="负责人姓名" align="center" prop="principalName" />
      <el-table-column label="负责人电话" align="center" prop="principalPhone" />
      <el-table-column label="负责人微信" align="center" prop="principalWx" />
      <el-table-column label="所在镇街园区" align="center" prop="orgAddr" />
      <el-table-column label="拟引进人才姓名" align="center" prop="talentName" />
      <el-table-column label="出生年月" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="本单位入职时间" align="center" prop="hiredate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.hiredate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否留学生" align="center" prop="isForeignStudent" :formatter="isForeignStudentFormat" />
      <!-- <el-table-column label="境外留学高校中文名称" align="center" prop="foreignSchoolNameCn" />
      <el-table-column label="境外留学高校英文名称" align="center" prop="foreignSchoolNameEn" />
      <el-table-column label="世界排名" align="center" prop="number" />
      <el-table-column label="所学专业" align="center" prop="specialtyNameCn" />
      <el-table-column label="所学专业" align="center" prop="specialtyNameEn" />
      <el-table-column label="学位" align="center" prop="degree" />
      <el-table-column label="毕业日期" align="center" prop="graduationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.graduationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="在境外学习时长" align="center" prop="learnDay" />
      <el-table-column label="本科学校名称" align="center" prop="uSchoolName" />
      <el-table-column label="本科专业名称" align="center" prop="uSpecialtyName" />
      <el-table-column label="本科毕业时间" align="center" prop="uGraduationTime" />
      <el-table-column label="本科学位" align="center" prop="uDegree" />
      <el-table-column label="硕士学校名称" align="center" prop="masterSchoolName" />
      <el-table-column label="硕士专业名称" align="center" prop="masterSpecialtyName" />
      <el-table-column label="硕士毕业时间" align="center" prop="masterGraduationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.masterGraduationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="硕士学位" align="center" prop="masterDegree" />
      <el-table-column label="博士学校名称" align="center" prop="phdSchoolName" />
      <el-table-column label="博士专业名称" align="center" prop="phdSpecialtyName" />
      <el-table-column label="博士毕业时间" align="center" prop="phdGraduationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.phdGraduationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="博士学位" align="center" prop="phdDegree" />-->
      <el-table-column label="审核结果" align="center" prop="result" :formatter="resultFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['talent:talentBaseInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['talent:talentBaseInfo:remove']"
          >删除</el-button>-->
          <el-button
            v-show="scope.row.result=='1'||scope.row.result=='2'"
            v-hasPermi="['talent:talentBaseInfo:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看</el-button>
          <el-button
            v-show="scope.row.result=='3'"
            v-hasPermi="['talent:talentBaseInfo:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--
    <el-dialog :title="title" :visible.sync="open" append-to-body>

      <detail :id="selectedid" />

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    -->
    <detail ref="detail" />

  </div>
</template>

    <!-- 添加或修改人才引进基本信息对话框
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
       <el-row>
       <el-col :span="12">
        <el-form-item label="公司名称" prop="orgName">
          <el-input v-model="form.orgName" placeholder="请输入公司名称" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="是否国高薪企业" prop="isHpEnterprise">
          <el-select v-model="form.isHpEnterprise" placeholder="请选择是否国高薪企业">
            <el-option
              v-for="dict in isHpEnterpriseOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        </el-col>
        </el-row>
        <el-row>
            <el-row>
              人力资源分管负责人联系方式
              <el-col :span="24">
                <el-form-item label="姓名" prop="principalName">
                  <el-input v-model="form.principalName" placeholder="请输入人力资源分管负责人姓名" />
                </el-form-item>
               </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                  <el-form-item label="电话" prop="principalPhone">
                    <el-input v-model="form.principalPhone" placeholder="请输入人力资源分管负责人电话" />
                  </el-form-item>
                 </el-col>
            </el-row>
            <el-row>
               <el-col :span="24">
                <el-form-item label="微信" prop="principalWx">
                  <el-input v-model="form.principalWx" placeholder="请输入人力资源分管负责人微信" />
                </el-form-item>
               </el-col>
             </el-row>
        </el-row>
         <el-row>
         <el-col :span="12">
        <el-form-item label="所在镇街园区" prop="orgAddr">
          <el-select v-model="form.orgAddr" placeholder="请选择所在镇街园区">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        </el-col>
         </el-row>
        <el-form-item label="拟引进人才姓名" prop="talentName">
          <el-input v-model="form.talentName" placeholder="请输入拟引进人才姓名" />
        </el-form-item>
        <el-form-item label="出生年月" prop="birthday">
          <el-date-picker clearable size="small"
            v-model="form.birthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择出生年月">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="本单位入职时间" prop="hiredate">
          <el-date-picker clearable size="small"
            v-model="form.hiredate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择本单位入职时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否留学生" prop="isForeignStudent">
          <el-select v-model="form.isForeignStudent" placeholder="请选择是否留学生">
            <el-option
              v-for="dict in isForeignStudentOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="境外留学高校中文名称" prop="foreignSchoolNameCn">
          <el-input v-model="form.foreignSchoolNameCn" placeholder="请输入境外留学高校中文名称" />
        </el-form-item>
        <el-form-item label="境外留学高校英文名称" prop="foreignSchoolNameEn">
          <el-input v-model="form.foreignSchoolNameEn" placeholder="请输入境外留学高校英文名称" />
        </el-form-item>
        <el-form-item label="世界排名" prop="number">
          <el-input v-model="form.number" placeholder="请输入世界排名" />
        </el-form-item>
        <el-form-item label="所学专业" prop="specialtyNameCn">
          <el-input v-model="form.specialtyNameCn" placeholder="请输入所学专业" />
        </el-form-item>
        <el-form-item label="所学专业" prop="specialtyNameEn">
          <el-input v-model="form.specialtyNameEn" placeholder="请输入所学专业" />
        </el-form-item>
        <el-form-item label="学位" prop="degree">
          <el-input v-model="form.degree" placeholder="请输入学位" />
        </el-form-item>
        <el-form-item label="毕业日期" prop="graduationTime">
          <el-date-picker clearable size="small"
            v-model="form.graduationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择毕业日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="在境外学习时长" prop="learnDay">
          <el-input v-model="form.learnDay" placeholder="请输入在境外学习时长" />
        </el-form-item>
        <el-form-item label="本科学校名称" prop="uSchoolName">
          <el-input v-model="form.uSchoolName" placeholder="请输入本科学校名称" />
        </el-form-item>
        <el-form-item label="本科专业名称" prop="uSpecialtyName">
          <el-input v-model="form.uSpecialtyName" placeholder="请输入本科专业名称" />
        </el-form-item>
        <el-form-item label="本科毕业时间" prop="uGraduationTime">
          <el-input v-model="form.uGraduationTime" placeholder="请输入本科毕业时间" />
        </el-form-item>
        <el-form-item label="本科学位" prop="uDegree">
          <el-input v-model="form.uDegree" placeholder="请输入本科学位" />
        </el-form-item>
        <el-form-item label="硕士学校名称" prop="masterSchoolName">
          <el-input v-model="form.masterSchoolName" placeholder="请输入硕士学校名称" />
        </el-form-item>
        <el-form-item label="硕士专业名称" prop="masterSpecialtyName">
          <el-input v-model="form.masterSpecialtyName" placeholder="请输入硕士专业名称" />
        </el-form-item>
        <el-form-item label="硕士毕业时间" prop="masterGraduationTime">
          <el-date-picker clearable size="small"
            v-model="form.masterGraduationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择硕士毕业时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="硕士学位" prop="masterDegree">
          <el-input v-model="form.masterDegree" placeholder="请输入硕士学位" />
        </el-form-item>
        <el-form-item label="博士学校名称" prop="phdSchoolName">
          <el-input v-model="form.phdSchoolName" placeholder="请输入博士学校名称" />
        </el-form-item>
        <el-form-item label="博士专业名称" prop="phdSpecialtyName">
          <el-input v-model="form.phdSpecialtyName" placeholder="请输入博士专业名称" />
        </el-form-item>
        <el-form-item label="博士毕业时间" prop="phdGraduationTime">
          <el-date-picker clearable size="small"
            v-model="form.phdGraduationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择博士毕业时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="博士学位" prop="phdDegree">
          <el-input v-model="form.phdDegree" placeholder="请输入博士学位" />
        </el-form-item>
        <el-form-item label="审核结果" prop="result">
          <el-select v-model="form.result" placeholder="请选择审核结果">
            <el-option
              v-for="dict in resultOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
-->

<script>
import { listTalentBaseInfo, getTalentBaseInfo, delTalentBaseInfo, addTalentBaseInfo, updateTalentBaseInfo, exportTalentBaseInfo } from '@/api/talent/talentBaseInfo'
import detail from '@/views/talent/talentDetail/index.vue'

export default {
  name: 'TalentBaseInfo',
  components: {
    'detail': detail
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人才引进基本信息表格数据
      talentBaseInfoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 是否国高薪企业字典
      isHpEnterpriseOptions: [],
      // 是否留学生字典
      isForeignStudentOptions: [],
      // 审核结果字典
      resultOptions: [],
      // 审核结果字典
      orgAddrOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgName: null,
        isHpEnterprise: null,
        principalName: null,
        principalPhone: null,
        principalWx: null,
        orgAddr: null,
        talentName: null,
        birthday: null,
        hiredate: null,
        isForeignStudent: null,
        foreignSchoolNameCn: null,
        foreignSchoolNameEn: null,
        number: null,
        specialtyNameCn: null,
        specialtyNameEn: null,
        degree: null,
        graduationTime: null,
        learnDay: null,
        uSchoolName: null,
        uSpecialtyName: null,
        uGraduationTime: null,
        uDegree: null,
        masterSchoolName: null,
        masterSpecialtyName: null,
        masterGraduationTime: null,
        masterDegree: null,
        phdSchoolName: null,
        phdSpecialtyName: null,
        phdGraduationTime: null,
        phdDegree: null,
        result: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      selectedid: ''
    }
  },
  created() {
    this.getList()
    this.getDicts('sys_yes_no').then(response => {
      this.isHpEnterpriseOptions = response.data
    })
    this.getDicts('sys_yes_no').then(response => {
      this.isForeignStudentOptions = response.data
    })
    this.getDicts('talent_result').then(response => {
      this.resultOptions = response.data
    })
    this.getDicts('talent_fund_place').then(response => {
      this.orgAddrOptions = response.data
    })
  },
  methods: {
    /** 查询人才引进基本信息列表 */
    getList() {
      this.loading = true
      listTalentBaseInfo(this.queryParams).then(response => {
        this.talentBaseInfoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 是否国高薪企业字典翻译
    isHpEnterpriseFormat(row, column) {
      return this.selectDictLabel(this.isHpEnterpriseOptions, row.isHpEnterprise)
    },
    // 是否留学生字典翻译
    isForeignStudentFormat(row, column) {
      return this.selectDictLabel(this.isForeignStudentOptions, row.isForeignStudent)
    },
    // 是否留学生字典翻译
    resultFormat(row, column) {
      return this.selectDictLabel(this.resultOptions, row.result)
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        talentBaseInfoId: null,
        orgName: null,
        isHpEnterprise: null,
        principalName: null,
        principalPhone: null,
        principalWx: null,
        orgAddr: null,
        talentName: null,
        birthday: null,
        hiredate: null,
        isForeignStudent: null,
        foreignSchoolNameCn: null,
        foreignSchoolNameEn: null,
        number: null,
        specialtyNameCn: null,
        specialtyNameEn: null,
        degree: null,
        graduationTime: null,
        learnDay: null,
        uSchoolName: null,
        uSpecialtyName: null,
        uGraduationTime: null,
        uDegree: null,
        masterSchoolName: null,
        masterSpecialtyName: null,
        masterGraduationTime: null,
        masterDegree: null,
        phdSchoolName: null,
        phdSpecialtyName: null,
        phdGraduationTime: null,
        phdDegree: null,
        result: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.talentBaseInfoId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加人才引进基本信息'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const talentBaseInfoId = row.talentBaseInfoId || this.ids
      this.$refs.detail.init('才引进基本信息', talentBaseInfoId)
      // this.reset()
      // const talentBaseInfoId = row.talentBaseInfoId || this.ids
      // this.selectedid = talentBaseInfoId
      // getTalentBaseInfo(talentBaseInfoId).then(response => {
      //   this.form = response.data
      //   this.open = true
      //   this.title = '修改人才引进基本信息'
      // })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.talentBaseInfoId != null) {
            updateTalentBaseInfo(this.form).then(response => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addTalentBaseInfo(this.form).then(response => {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const talentBaseInfoIds = row.talentBaseInfoId || this.ids
      this.$confirm('是否确认删除人才引进基本信息编号为"' + talentBaseInfoIds + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delTalentBaseInfo(talentBaseInfoIds)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有人才引进基本信息数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return exportTalentBaseInfo(queryParams)
      }).then(response => {
        this.download(response.msg)
      })
    }
  }
}
</script>
